/*
 * @Author: ReinerLau lk850593913@gmail.com
 * @Date: 2022-09-14 13:24:35
 * @LastEditors: ReinerLau lk850593913@gmail.com
 * @LastEditTime: 2022-10-28 13:31:30
 * @FilePath: \robot\src\api\robot-camera.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { request } from '@/utils'

interface CameraParams {
  rid?: string | number
  rtype?: string
  id?: string | number
  [key: string]: any
}

interface CameraData {
  id?: string | number
  name?: string
  ip?: string
  port?: number
  username?: string
  password?: string
  [key: string]: any
}

/**
 * @description: 根据机器人编码和类型获取绑定的摄像头
 * @param code 机器人编码
 * @param type 机器人类型
 * @return {Promise<any>}
 */
export function getByCode(code: string | number, type: string): Promise<any> {
  return request({
    url: `/camera/v1/getbyrid/${code}&${type}`,
    method: "get",
  });
}

export function getCameraList(params: CameraParams): Promise<any> {
  return request({
    url: "/camera/v1/",
    method: "get",
    params: params,
  });
}

export function setCameraRid(params: CameraParams): Promise<any> {
  return request({
    url: "/camera/v1/updateToRid",
    method: "post",
    params: params,
  });
}

export function fetchList(params: CameraParams): Promise<any> {
  return request({
    url: "/camera/v1/",
    method: "get",
    params: params,
  });
}

export function createRobotCamera(data: CameraData): Promise<any> {
  return request({
    url: "/camera/v1/",
    method: "post",
    data: data,
  });
}

export function deleteRobotCamera(id: string | number): Promise<any> {
  return request({
    url: `/camera/v1/${id}`,
    method: "delete",
  });
}

export function updateRobotCamera(id: string | number, data: CameraData): Promise<any> {
  return request({
    url: `/camera/v1/`,
    method: "put",
    data: data,
  });
}

export function getCamera(id: string | number): Promise<any> {
  return request({
    url: `/camera/v1/getone/${id}`,
    method: "get",
  });
}
